package com.aaa.mks.controller;

import com.aaa.common.bo.Coupon;
import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mks.entity.CouponHistory;
import com.aaa.mks.service.CouponHistoryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CouponHistory)表控制层
 *
 * @author makejava
 * @since 2020-12-14 11:51:50
 */
@RestController
@RequestMapping("couponHistory")
public class CouponHistoryController {
    /**
     * 服务对象
     */
    @Resource
    private CouponHistoryService couponHistoryService;


    /**
     *根据会员编号或者店铺ID 获取该会员的所有可用优惠券
     * @param shopId
     * @param memberId
     * @return
     */
    @GetMapping("/getCouponListByMemberId")
    public List<Coupon> getCouponListByMemberId(@RequestParam("shopId") Long shopId, @RequestParam("memberId") Long  memberId){
        /*long  shopId = couponHistory.getCouponId();
        long  memberId = couponHistory.getMemberId();*/
        return  couponHistoryService.getCouponListByMemberId(shopId,memberId);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public CouponHistory selectOne(Long id) {
        return this.couponHistoryService.queryById (id);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param pageNo        第几页
     * @param pageSize      每页显示数量
     * @param couponHistory 实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有分页加条件查询")
    public Result queryAll(@RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize, @RequestBody CouponHistory couponHistory) {
        return this.couponHistoryService.queryAll (pageNo, pageSize, couponHistory);
    }

    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Long id) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.couponHistoryService.deleteById (id));
    }

    /**
     * 更新
     *
     * @param @param couponHistory 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody CouponHistory couponHistory) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.couponHistoryService.update (couponHistory));
    }

    /**
     * 添加
     *
     * @param @param couponHistory 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody CouponHistory couponHistory) {
        return new Result (ReturnStatus.SUCCESS.getReturnCode (),
                ReturnStatus.SUCCESS.getReturnMsg (), this.couponHistoryService.insert (couponHistory));
    }
}